//
//  WMChangePsdView.m
//  witMorning
//
//  Created by Mac mini on 2018/2/1.
//  Copyright © 2018年 zt. All rights reserved.
//

#import "WMChangePsdView.h"

@implementation WMChangePsdView


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, 50)];
        lab.text = @"修改密码";
        lab.textColor = [UIColor whiteColor];
        lab.backgroundColor = RGB(10, 99, 207, 1);
        lab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:lab];
        
        NSArray *arr = @[@"旧密码:",@"新密码:",@"确认密码:"];
        for (int i = 0; i<3; i++) {
            UIView *view = [self createViewWithFrame:CGRectMake(20, 50+50*i+10, frame.size.width-30, 50) andTag:i*10 andTitle:arr[i]];
            [self addSubview:view];
        }
      
        UIButton *submit = [[UIButton alloc]initWithFrame:CGRectMake(frame.size.width/4-30, frame.size.height-60, 60, 40)];
        [submit setTitle:@"确定" forState:UIControlStateNormal];
        [submit setTag:1000];
        [submit setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [submit setBackgroundColor:[UIColor lightGrayColor]];
        [submit addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:submit];
        UIButton *canncel = [[UIButton alloc]initWithFrame:CGRectMake(frame.size.width/4*3-30, frame.size.height-60, 60, 40)];
        [canncel setTitle:@"取消" forState:UIControlStateNormal];
         [canncel setTag:1001];
        [canncel setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [canncel setBackgroundColor:[UIColor lightGrayColor]];
         [canncel addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:canncel];
    }
    return self;
}

-(void)click:(UIButton *)button{
    
    for (UITextField *textf in self.textArray) {
        [textf resignFirstResponder];
    }
    
    if (self.changePsdCallBack) {
        self.changePsdCallBack(button.tag,self.textArray);
    }
}

-(UIView *)createViewWithFrame:(CGRect)frame andTag:(NSInteger)tag andTitle:(NSString *)title{
    
    UIView *view = [[UIView alloc]initWithFrame:frame];
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, 50)];
    lab.text = title;
    lab.textColor = [UIColor darkGrayColor];
    lab.textAlignment = NSTextAlignmentRight;
    [view addSubview:lab];
    
    UITextField *textF = [[UITextField alloc]initWithFrame:CGRectMake(90, 0, frame.size.width-90, 49)];
    textF.delegate = self;
    textF.tag = tag;
    [view addSubview:textF];
    
    if (!self.textArray) {
        _textArray = [NSMutableArray arrayWithCapacity:0];
    }
    [_textArray addObject:textF];
    
    UILabel *bottomLine = [[UILabel alloc]initWithFrame:CGRectMake(90, 49, frame.size.width-90, 1)];
    bottomLine.backgroundColor = [UIColor lightGrayColor];
    [view addSubview:bottomLine];
    
    return view;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
